﻿using System;

namespace test_9_20_C_Sharp
{
    class Program
    {
        static bool judge_prime(int num)
        {
            int i = 0;
            //寻找素数较优解，直接开根号
            for (i = 2; i <= Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                    return false;
            }
            //虽然2也是质数，但它无法找到另一个质素与它组成2
            //所以要排除
            if ((num % i) == 0)
                return false;
            else
                return true;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业3");
            //找素数，-素数，判断
            Console.WriteLine("请输入一个大于2的偶数:>");
            int num = Convert.ToInt32(Console.ReadLine());
            int i = 0;
            bool flag = false;//判断标志
            for (i = 2; i <= num; i++)
            {
                bool ret = judge_prime(i);
                if (ret && judge_prime(num - i))
                {
                    Console.WriteLine("哥德巴赫猜想成立");
                    Console.WriteLine(num + "=" + i + "+" + (num - i));
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                Console.WriteLine("哥德巴赫猜想不成立或输入数不为大于2的偶数!");
            }
        }

        static void Main2(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业3");
            int i = 0;
            int sum = 0;//五数和
            int flag = 0;//容量
            for (i = 1; i < 301; i++)
            {
                if ((i % 7) == 0)
                {
                    sum += i;
                    flag++;
                }
                if (flag == 5)
                {
                    Console.Write(sum + " ");
                    sum = 0;
                    flag = 0;
                }
            }
        }

        static int getMax(int a, int b, int c, int d)
        {
            int max = a;
            if (b > max)
                max = b;
            if (c > max)
                max = c;
            if (d > max)
                max = d;
            return max;
        }
        static void Main3(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业3");
            Console.WriteLine("请输入数1:>");
            int num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入数2:>");
            int num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入数3:>");
            int num3 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入数4:>");
            int num4 = Convert.ToInt32(Console.ReadLine());
            int max = getMax(num1, num2, num3, num4);
            Console.WriteLine("四数中最大数为" + max);
        }

        struct stu 
        {
            //结构体内数据
            public string name;
            public string sex;
            public int age;
            public double hight;
            public double weight;
        };
        static void Main4(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业3");
            stu s1;
            Console.WriteLine("请输入姓名:>");
            s1.name = Console.ReadLine();
            Console.WriteLine("请输入性别:>");
            s1.sex = Console.ReadLine();
            Console.WriteLine("请输入年龄:>");
            s1.age = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入身高:>");
            s1.hight = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("请输入体重:>");
            s1.weight = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("学生基本信息录入完成!");
            Console.WriteLine("信息如下:>");
            Console.Write("姓名" + '\t' + "性别" + '\t' + "年龄" + 
                '\t' + "身高" + '\t' + "体重" + '\n');
            Console.Write(s1.name+ '\t' + s1.sex + '\t' + s1.age + 
                '\t' + s1.hight + '\t' + s1.weight + '\n');
        }

        static bool judgePrime(int num)
        {
            int i = 2;
            //开平方循环，大大节省时间
            for (; i <= Math.Sqrt(num); i++)
            {
                if ((num) % i == 0)
                    return true;
            }
            return false;
        }
        static void Main5(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的课后作业3");
            Console.WriteLine("请输入左边界:>");
            int left = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入右边界:>");
            int right = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(left + "到" + right + "内的合数有:>");
            for (; left <= right; left++)
            {
                if (judgePrime(left))
                    Console.Write(left + " ");
            }
        }
    }
}
